package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.Stocklist;
import com.ruoyi.system.util.HtmlUtil;
import jdk.nashorn.internal.ir.IfNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.StockMapper;
import com.ruoyi.system.domain.Stock;
import com.ruoyi.system.service.IStockService;
import com.ruoyi.common.core.text.Convert;

/**
 * 股票数据Service业务层处理
 *
 * @author ruoyi
 * @date 2021-12-27
 */
@Service("IStockService")
public class StockServiceImpl implements IStockService {
    @Autowired
    private StockMapper stockMapper;

    @Autowired
    public RedisTemplate redisTemplate;

    @Autowired
    public HtmlUtil htmlUtil;

    public static Map<String, List<Stock>> stocksMap;

    /**
     * 查询股票数据
     *
     * @param id 股票数据主键
     * @return 股票数据
     */
    @Override
    public Stock selectStockById(Long id) {
        return stockMapper.selectStockById(id);
    }

    @Override
    public Stock getOne(Stock stocklist) {
        return Optional.ofNullable(this.selectStockList(stocklist)).map(stocklists -> {
            if (stocklists.size() > 0) {
                return stocklists.get(0);
            }
            return null;
        }).orElse(null);

    }

    /**
     * 查询股票数据列表
     *
     * @param stock 股票数据
     * @return 股票数据
     */
    @Override
    public List<Stock> selectStockList(Stock stock) {
        return stockMapper.selectStockList(stock);
    }

    /**
     * 新增股票数据
     *
     * @param stock 股票数据
     * @return 结果
     */
    @Override
    public int insertStock(Stock stock) {
        return stockMapper.insertStock(stock);
    }

    /**
     * 修改股票数据
     *
     * @param stock 股票数据
     * @return 结果
     */
    @Override
    public int updateStock(Stock stock) {
        return stockMapper.updateStock(stock);
    }

    /**
     * 批量删除股票数据
     *
     * @param ids 需要删除的股票数据主键
     * @return 结果
     */
    @Override
    public int deleteStockByIds(String ids) {
        return stockMapper.deleteStockByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除股票数据信息
     *
     * @param id 股票数据主键
     * @return 结果
     */
    @Override
    public int deleteStockById(Long id) {
        return stockMapper.deleteStockById(id);
    }
}
